package com.ljx.designMode.template;

import java.nio.channels.Pipe;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2022/11/10 15:45
 * @Version 1.0
 */
public class TemplateTest02 {
	public static void main(String[] args) {
		AreaPerimeter areaPerimeter=new Square(4);
		AreaPerimeter areaPerimeter1=new Circle(4);
		areaPerimeter.areaPerimeter();
		areaPerimeter1.areaPerimeter();
	}
}

abstract class AreaPerimeter{
	/**
	 * 求面积方法
	 * @return
	 */
	public	abstract void area();

	/**
	 * 求周长方法
	 * @return
	 */
	public abstract void perimeter();

	public void areaPerimeter(){
		area();
		perimeter();
	}
}

class Circle extends AreaPerimeter{

	private double radius;

	public Circle(double radius) {
		this.radius = radius;
	}

	@Override
	public void area() {

		double area=radius*radius* 3.14;

		System.out.println("圆面积为："+area);
	}

	@Override
	public void perimeter() {
		double perimeter=radius*2*3.14;
		System.out.println("圆的周长为："+perimeter);
	}
}

class Square extends AreaPerimeter{
	private double square;

	public Square(double square) {
		this.square = square;
	}

	@Override
	public void area() {
		double area=square*square;
		System.out.println("正方形的面积为:"+area);
	}

	@Override
	public void perimeter() {
		double perimeter=square*4;
		System.out.println("正方形的周长为："+perimeter);
	}
}